from pydantic import BaseModel, field_validator, Field

from common.exception.biz_exception import BizException
from common.response.biz_response_code import ERROR
from model.request.sys.register_user_profile_request import RegisterUserProfileRequest


class RegisterUserRequest(BaseModel):
    username: str
    password: str
    enable: bool
    profile: RegisterUserProfileRequest
    role_ids: list[int] = Field(..., alias="roleIds")

    @field_validator('username')
    def validate_username(cls, v):  # noqa
        min_length = 3
        max_length = 50
        if not (min_length <= len(v) <= max_length):
            raise BizException(ERROR, 'The username length is not within the specified range')
        return v

    @field_validator('password')
    def validate_password(cls, v):  # noqa
        min_length = 8
        max_length = 50
        if not (min_length <= len(v) <= max_length):
            raise BizException(ERROR, 'The password length is not within the specified range')
        return v
